package Task;

/**
 * Created with IntelliJ IDEA.
 * Description:Java多线程实验三代码
 */
class MyThreadTest extends Thread {
    static Object object = new Object();
    private static int note = 50;
    public MyThreadTest(String name) {
        super(name);
    }

    @Override
    public void run() {
        while(note > 0) {
            synchronized (object) {
                if(note > 0) {
                    System.out.println(this.getName() + "---发出的笔记" + note);
                    note--;
                }
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Test3 {

    public static void main(String[] args) {
        new MyThreadTest("王老师").start();
        new MyThreadTest("李老师").start();
        new MyThreadTest("张老师").start();
    }
}
